package require1;

import org.apache.storm.Config;
import org.apache.storm.LocalCluster;
import org.apache.storm.StormSubmitter;
import org.apache.storm.topology.TopologyBuilder;

public class WebLogMain {
    public static void main(String[] args) {

        //创建拓扑
        TopologyBuilder builder = new TopologyBuilder();
        builder.setSpout("WebLogSpout",new WebLogSpout(),1);
        builder.setBolt("WebLogBolt",new WebLogBolt(),1).shuffleGrouping("WebLogSpout");

        //配置Worker开启个数
        Config conf =  new Config();
        conf.setNumWorkers(2);

        //提交程序
        if(args.length>0){
            //如果args大于0，说明在集群上运行
            //分布式提交
            try {
                StormSubmitter.submitTopology(args[0],conf,builder.createTopology());
            } catch (Exception e) {
                e.printStackTrace();

            }
        }else{
            //本地模式提交
            try {
                LocalCluster localCluster = new LocalCluster();
                localCluster.submitTopology("WebLogTopology", conf, builder.createTopology());
            }catch (Exception e){
                e.printStackTrace();
            }


        }
    }
}
